﻿using SubstringSearcher.Model;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.IO;
using System.Text;

namespace Problem5SubstringSearcher.Test
{
    [TestClass()]
    public class SubstringSearcherTest
    {
        [TestMethod()]
        public void GetFirstLineContainingTest()
        {
            string text = @"Here is some
text that we will be
searching in text and bang
text what
text. This will only return the 1st line, why am i writing more of this ?";
                       
            byte[] buffer = Encoding.UTF8.GetBytes(text);
            MemoryStream memoryStream = new MemoryStream(buffer);
            StreamReader reader = new StreamReader(memoryStream);
            string substring = "text";
            string expected = "text that we will be";
            string actual = SubstringSearcher.Model.SubstringSearcher.GetFirstLineContaining(reader, substring);
            Assert.AreEqual(expected, actual);            
        }

        [TestMethod()]
        public void GetFirstLineContainingTest4()
        {
            string text = @"Here is some
text that we will be
searching in text and bang
text what
text. This will only return the 1st line, why am i writing more of this ?";

            byte[] buffer = Encoding.ASCII.GetBytes(text);
            MemoryStream memoryStream = new MemoryStream(buffer);
            StreamReader reader = new StreamReader(memoryStream);
            string substring = "text";
            string expected = "text that we will be";
            string actual = SubstringSearcher.Model.SubstringSearcher.GetFirstLineContaining(reader, substring);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void GetFirstLineContainingTest2()
        {
            string text = @"Here is some
text that we will be
searching in text and bang
text what
text. This will only return the 1st line, why am i writing more of this ?";

            byte[] buffer = Encoding.UTF8.GetBytes(text);
            MemoryStream memoryStream = new MemoryStream(buffer);
            StreamReader reader = new StreamReader(memoryStream);
            string substring = " ";
            string expected = "Here is some";
            string actual = SubstringSearcher.Model.SubstringSearcher.GetFirstLineContaining(reader, substring);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void GetFirstLineContainingTest3()
        {
            string text = "";
            byte[] buffer = Encoding.UTF8.GetBytes(text);
            MemoryStream memoryStream = new MemoryStream(buffer);
            StreamReader reader = new StreamReader(memoryStream);
            string substring = "s";
            string expected = null;
            string actual = SubstringSearcher.Model.SubstringSearcher.GetFirstLineContaining(reader, substring);
            Assert.AreEqual(expected, actual);
        }

        
    }
}
